package com.huawei.appmarket.service.infoflow.view.widget;

import android.content.Context;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.animation.AccelerateInterpolator;
import android.widget.ListAdapter;
import android.widget.Scroller;
import com.huawei.appgallery.festivalanimation.particle.modifiers.SizeModifier;
import com.huawei.appgallery.foundation.ui.framework.widget.PullUpListView;
import com.huawei.appmarket.service.infoflow.view.widget.HeaderView.d;
import java.lang.ref.WeakReference;
import o.dky.c;
import o.Logger;

public class PullDownListView extends PullUpListView {
    private int ʻ;
    private float ʼ = SizeModifier.STABLE_STATE_SCALE;
    private int ʽ;
    private boolean ˊॱ = false;
    private b ˋॱ;
    private boolean ˏॱ = true;
    private HeaderView ॱॱ;
    private boolean ᐝ = true;

    static class a implements d {
        private WeakReference<PullDownListView> ˎ;
        private boolean ॱ = true;

        public a(PullDownListView pullDownListView, boolean z) {
            this.ˎ = new WeakReference(pullDownListView);
            this.ॱ = z;
        }

        public void ˎ() {
            if (!this.ॱ) {
                return;
            }
            if (this.ˎ != null) {
                PullDownListView pullDownListView = (PullDownListView) this.ˎ.get();
                if (pullDownListView != null) {
                    ˎ(pullDownListView);
                    if (pullDownListView.ʽ <= 0) {
                        Logger.e("PullDownListView", "HeaderLayoutEnd, run, listView.headerHeight == 0");
                        return;
                    } else if (pullDownListView.ˊॱ) {
                        pullDownListView.ʽॱ();
                        return;
                    } else if (pullDownListView.ˋॱ != null) {
                        pullDownListView.ˋॱ.ˊ();
                        return;
                    } else {
                        return;
                    }
                }
                Logger.e("PullDownListView", "HeaderLayoutEnd, run, listView == null");
                return;
            }
            Logger.e("PullDownListView", "HeaderLayoutEnd, run, listViewRef == null");
        }

        private void ˎ(PullDownListView pullDownListView) {
            pullDownListView.ʽ = pullDownListView.ॱॱ.getHeight();
            if (pullDownListView.ʽ <= 0 || !pullDownListView.ˊ.isFinished()) {
                if (pullDownListView.getContext().getResources().getConfiguration().fontScale <= 1.0f) {
                    pullDownListView.ʽ = (int) pullDownListView.getResources().getDimension(c.ˊˋ);
                } else {
                    pullDownListView.ʽ = (int) pullDownListView.getResources().getDimension(c.ˊᐝ);
                }
                Logger.ˎ("PullDownListView", "initHeaderInfo, default,headerHeight = " + pullDownListView.ʽ);
            }
            pullDownListView.ˊ(1);
            if (Logger.ˎ()) {
                Logger.ˏ("PullDownListView", "initHeaderInfo, headerHeight = " + pullDownListView.ʽ);
            }
        }
    }

    public interface b {
        void ˊ();
    }

    public PullDownListView(Context context) {
        super(context);
    }

    public PullDownListView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
    }

    public PullDownListView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
    }

    public void ˊ(Context context) {
        super.ˊ(context);
        setOverScrollMode(2);
    }

    public void setAdapter(ListAdapter listAdapter) {
        super.setAdapter(listAdapter);
        ˏ(getContext());
    }

    public void setSupportDownRefresh(boolean z) {
        this.ˏॱ = z;
        if (this.ˏॱ) {
            setOverScrollMode(2);
            return;
        }
        setOverScrollMode(0);
        if (this.ॱॱ != null) {
            this.ॱॱ.setVisibility(8);
        }
    }

    public Parcelable onSaveInstanceState() {
        Parcelable onSaveInstanceState = super.onSaveInstanceState();
        if (!(onSaveInstanceState instanceof SavedState)) {
            return onSaveInstanceState;
        }
        SavedState savedState = (SavedState) onSaveInstanceState;
        savedState.ˊ(this.ʽ);
        return savedState;
    }

    public void onRestoreInstanceState(Parcelable parcelable) {
        super.onRestoreInstanceState(parcelable);
        if (parcelable instanceof SavedState) {
            this.ʽ = ((SavedState) parcelable).ˏ();
            invalidate();
        }
    }

    public void setHeaderLayoutListener(b bVar) {
        this.ˋॱ = bVar;
    }

    public boolean ᐝॱ() {
        return this.ᐝ;
    }

    public void setNeedHeaderView(boolean z) {
        this.ᐝ = z;
    }

    public Scroller ॱ(Context context) {
        return new Scroller(context, new AccelerateInterpolator(1.5f));
    }

    public void setLoadingTips(String str) {
        if (!TextUtils.isEmpty(str) && this.ॱॱ != null) {
            this.ॱॱ.setLoadingTips(str);
        }
    }

    public void ʽॱ() {
        if (!this.ˏॱ) {
            return;
        }
        if (this.ʽ <= 0) {
            Logger.e("PullDownListView", "startPullDownRefresh, headerHeight = " + this.ʽ);
        } else if (!ॱॱ()) {
            ˏ(this.ʽ);
            ˈ();
            if (Logger.ˎ()) {
                Logger.ˏ("PullDownListView", "startPullDownRefresh, onPullDownRefresh");
            }
        } else if (this.ॱॱ != null && this.ॱॱ.ॱ() == 0) {
            setmPullRefreshing(false);
            if (Logger.ˎ()) {
                Logger.ˏ("PullDownListView", "startPullDownRefresh, setmPullRefreshing false");
            }
        }
    }

    public void setAutoPullDownRefresh(boolean z) {
        this.ˊॱ = z;
    }

    public void ʼॱ() {
        if (Logger.ˎ()) {
            Logger.ˏ("PullDownListView", "finishRefresh");
        }
        ˊ(300);
    }

    public boolean onTouchEvent(MotionEvent motionEvent) {
        if (!this.ˏॱ) {
            return super.onTouchEvent(motionEvent);
        }
        if (this.ʼ == SizeModifier.STABLE_STATE_SCALE) {
            this.ʼ = motionEvent.getRawY();
        }
        switch (motionEvent.getAction()) {
            case 0:
                this.ʼ = motionEvent.getRawY();
                break;
            case 2:
                float rawY = motionEvent.getRawY() - this.ʼ;
                this.ʼ = motionEvent.getRawY();
                if (getFirstVisiblePosition() != 0 || rawY <= 0.0f || ॱॱ()) {
                    if (Logger.ˎ()) {
                        Logger.ˋ("PullDownListView", "onTouchEvent, ACTION_MOVE, deltaY = " + rawY + ", mPullRefreshing = " + ॱॱ());
                        break;
                    }
                }
                ॱ((int) (rawY / 2.0f));
                break;
                break;
            default:
                this.ʼ = SizeModifier.STABLE_STATE_SCALE;
                ʿ();
                break;
        }
        return super.onTouchEvent(motionEvent);
    }

    private void ʿ() {
        if (!(this.ॱॱ == null || this.ॱॱ.ॱ() <= this.ʽ || ॱॱ())) {
            ˈ();
            if (Logger.ˎ()) {
                Logger.ˏ("PullDownListView", "onTouchEvent, onPullDownRefresh");
            }
        }
        ʾ();
    }

    public void computeScroll() {
        if (this.ˏॱ) {
            if (this.ˊ.computeScrollOffset() && (this.ʻ == 0 || this.ʻ == 1)) {
                ˏ(this.ˊ.getCurrY());
            }
            postInvalidate();
            return;
        }
        super.computeScroll();
    }

    private void ˈ() {
        if (!(this.ॱॱ == null || this.ॱॱ.getVisibility() == 0)) {
            this.ॱॱ.setVisibility(0);
        }
        if (this.ˎ != null) {
            setmPullRefreshing(true);
            this.ˎ.ˈॱ();
        }
    }

    private void ॱ(int i) {
        if (this.ॱॱ == null) {
            Logger.ˋ("PullDownListView", "updateHeaderHeight, headerView == null");
            setmPullRefreshing(false);
            return;
        }
        if (this.ॱॱ.getVisibility() != 0) {
            this.ॱॱ.setVisibility(0);
        }
        ˏ(this.ॱॱ.ॱ() + i);
    }

    private void ʾ() {
        if (this.ॱॱ == null) {
            Logger.e("PullDownListView", "resetHeaderHeight, headerView == null");
            setmPullRefreshing(false);
            return;
        }
        int ॱ = this.ॱॱ.ॱ();
        if (ॱ == 0) {
            setmPullRefreshing(false);
            Logger.ˋ("PullDownListView", "resetHeaderHeight, height == 0");
        } else if (!ॱॱ() || ॱ > this.ʽ) {
            int i;
            if (!ॱॱ() || ॱ <= this.ʽ) {
                i = 0;
            } else {
                i = this.ʽ;
            }
            this.ʻ = 0;
            this.ˊ.startScroll(0, ॱ, 0, i - ॱ, 300);
        } else {
            Logger.ˋ("PullDownListView", "resetHeaderHeight, height <= this.headerHeight: height = " + ॱ);
        }
    }

    private void ˏ(int i) {
        if (this.ॱॱ != null) {
            this.ॱॱ.setVisibleHeight(i);
        }
    }

    private void ˏ(Context context) {
        if (ᐝॱ() && this.ॱॱ == null) {
            this.ॱॱ = new HeaderView(context);
            this.ॱॱ.setILayoutEndListener(new a(this, this.ˏॱ));
            this.ॱॱ.setVisibility(4);
            addHeaderView(this.ॱॱ);
        }
    }

    private void ˊ(int i) {
        if (this.ॱॱ == null) {
            Logger.e("PullDownListView", "hideHeaderView, headerView == null");
            return;
        }
        int ॱ = this.ॱॱ.ॱ();
        if (ॱ != 0) {
            this.ʻ = 1;
            this.ˊ.startScroll(0, ॱ, 0, -ॱ, i);
            if (Logger.ˎ()) {
                Logger.ˏ("PullDownListView", "hideHeaderView");
            }
        } else if (Logger.ˎ()) {
            Logger.ˋ("PullDownListView", "hideHeaderView, height == 0");
        }
    }
}
